package com.nuanshui.heatedloan.extension;

import org.apache.commons.lang3.StringUtils;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import com.nuanshui.heatedloan.fund.enums.PaymentBizType;

public class PayBizTypeEnumArgumentResolver implements  HandlerMethodArgumentResolver {

	@Override
	public boolean supportsParameter(MethodParameter parameter) {
		return Enum.class.isAssignableFrom(parameter.getParameterType());
	}

	@Override
	public Object resolveArgument(MethodParameter parameter,
			ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
			WebDataBinderFactory binderFactory) throws Exception {		
		String name = parameter.getParameterName();
		String value =  webRequest.getParameter(name);
		if(StringUtils.isNotEmpty(value)){
			return PaymentBizType.getPayBizType(value);
		}
		return null;
	}
	
	public static void main(String[] args) {
		Object obj = "";
		
		System.out.println(PaymentBizType.class.isAssignableFrom(obj.getClass()));
	}

}
